# Maintainer: David Runge <dvzrv@archlinux.org>

_name=pywlroots
pkgname=python-pywlroots
pkgver=0.16.6
pkgrel=2
pkgdesc="Python binding to the wlroots library using cffi"
arch=(loong64 x86_64)
url="https://github.com/flacjacket/pywlroots"
license=(NCSA)
depends=(
  glibc
  python
  python-cffi
  python-pywayland
  python-xkbcommon
  wlroots0.16
)
makedepends=(
  python-build
  python-installer
  python-setuptools
  python-wheel
)
checkdepends=(python-pytest)
provides=(pywlroots)
conflicts=(pywlroots)
replaces=(pywlroots)
source=($_name-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz)
sha512sums=('21d58dbb1c17bbc25ce9bb6d8265fb90e61ab41f1c8e6e32c99e7a2827139fa848589f35df9467a6a9ea1b5212af1007388549167b9c63bf09f5262aac6fc7f8')
b2sums=('0752c0511b1a9530d67c868e337bb2aba556111693a2c8e494d23d1e0ef1fcd9c08e4caf03bcc6a1029af5e9bb8059d037a08d726f611f72f065d1c38ab30226')

build() {
  export CFLAGS="$CFLAGS -I/usr/include/wlroots0.16"
  export LDFLAGS="$LDFLAGS -L/usr/lib/wlroots0.16"
  cd $_name-$pkgver
  python wlroots/ffi_build.py
  python -m build --wheel --no-isolation
}

check() {
  local _site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="test_dir/$_site_packages:$PYTHONPATH"
  pytest -vv
}

package() {
  depends+=(libwlroots.so=11)
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 README.rst -t "$pkgdir/usr/share/doc/$pkgname"
  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname"
}
